<template>
<div class="loginBox">
  <div v-if="logo" class="logo"><img class="logoImg" mode="aspectFit" :src="logo"></img></div>
  <formitems :models="models" ref="loginForm"></formitems>
  <button_ class="loginBtn" type="primary" size="default" :disabled="submiting" @click="submit">{{submiting ? '修改中...' : '修改密码'}}</button_>
</div>
</template>
<script type="text/javascript">
(function (G) {
  G.vue({
  "usingComponents": {
    "formitems": "/components/Form/Items/Items"
  },
  "navigationBarTitleText": "修改密码"
},{
    noLogin: true,
    data: {
      logo: '',
      models: {
        passWord: {
          label: '原密码',
          type: 'input',
          attr: { type: 'password' },
          rule: { NotNull: true }
        },
        newPassWord: {
          label: '新密码',
          type: 'input',
          attr: { type: 'password' },
          rule: { NotNull: true }
        },
        reNewPassWord: {
          label: '重复密码',
          type: 'input',
          attr: { type: 'password' },
          rule: { NotNull: true }
        }
      },
      userName:'',
      submiting: false
    },
    methods: {
      submit: function () {
        var _this = this;
        var data = this.selectComponent('#loginForm').submit();
        if (!data) return false;
        if(data.reNewPassWord != data.newPassWord){
          G.alertx('重复密码与新密码不一致!');
        }else{
          this.setData({ submiting: true });
          G.ajax('/changePassWord', function (ret) {
            _this.setData({ submiting: false });
            if (!ret.errorMsg) {
              G.alertx('密码修改成功!',function(){
                G.Storage.remove('userInfo');
                G.Storage.remove('user',1);
                G.reEnter('/pages/login/login');
              });
            }else{
              G.alertx(ret.errorMsg);
            }
          }, {
              meth: 'POST',
              data: {
                userName: this.getData('userName'),
                passWord: G.MD5(data.passWord),
                newPassWord: G.MD5(data.newPassWord)
              }
            })
        }
      }
    },
    mounted:function(options){
      if(options.userName) this.setData({userName:options.userName})
    }
  });
})(Y)

</script>
<style scoped>
.loginBox{
  padding-top:80rpx;
}
.Web .loginBox{
  width: 300px;
  border:1px solid #e4e4e4;
  margin: 0px auto;
  margin-top:80px;
  padding-top:0px;
  padding-bottom: 48px;
}
.logo{
  text-align: center;
}
.loginBtn{
  margin:0rpx 32rpx;
}
.Web .loginBtn{
  margin:0px 32px;
}
</style>